package kku.cs.hero;

import org.newdawn.slick.AngelCodeFont;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

import kku.cs.fgl.SpriteManager;
import kku.cs.fgl.actor.SpriteActor;

public class CharacterActor extends SpriteActor {
    String kname;
    float speed=0.5f;
    int power = 100;
    
	public CharacterActor(SpriteManager sprites,String name) {
		super(sprites);
		kname = name;		
		setKeyName(name+".down");
	}
	
	public void moveLeft(){
		setSpeed_x(-1*speed);
		setSpeed_y(0);
		setKeyName(kname+".left");
		setAnimate(true);
	}
	public void moveUp(){
		setSpeed_x(0);
		setSpeed_y(-1*speed);
		setKeyName(kname+".up");
		setAnimate(true);
	}
	public void moveDown(){
		setSpeed_x(0);
		setSpeed_y(1*speed);
		setKeyName(kname+".down");
		setAnimate(true);
	}
	public void moveRight(){
		setSpeed_x(1*speed);
		setSpeed_y(0);
		setKeyName(kname+".right");
		setAnimate(true);
	}
	public void stop(){
		setSpeed_x(0);
		setSpeed_y(0);
		setAnimate(false);
	}
	@Override
	public void calculateSpeed(int time) {
		super.calculateSpeed(time);
		if(getX()<0){
			setX(1);
			stop();
		}
		if(getY()<0){
			setY(1);
			stop();
		}
		if(getX()>1971){
			setX(1970);
			stop();
		}
		if(getY()>1971){
			setY(1970);
			stop();
		}
		setZorder((int)getBound().getMaxY());
	}	
	@Override
	public void paint(Graphics g) {
		super.paint(g);
		int w=getWidth();
		g.setColor(Color.red);
		g.fillRect(0,-5,50,5);
		g.setColor(Color.green);
		g.fillRect(0,-5,power/2,5);
		g.setColor(Color.white);
	}
	public String getKname() {
		return kname;
	}
	public void setKname(String kname) {
		this.kname = kname;
	}
	public float getSpeed() {
		return speed;
	}
	public void setSpeed(float speed) {
		this.speed = speed;
	}
	public int getPower() {
		return power;
	}

	public void setPower(int power) {
		this.power = power;
	}
}
